package edu.wpi.first.wpilibj.templates.commands;

import edu.wpi.first.wpilibj.Timer;

/**
 *
 * @author Jarrod Risley
 */
public class Shooter extends CommandBase {
    private final double kShotDelay = 0.4; // seconds

    int shooterMode = 0; // This should be either 1, 0, -1 ONLY!!!!
    boolean isFinished = false;
    double startTime = 0;

    public Shooter(int mode) {
        // Use requires() here to declare subsystem dependencies
        // eg. requires(chassis);
        //requires(shooterSubsystem);
        shooterMode = mode;
        System.out.println("Constructed Shooter mode - " + shooterMode);
    }

    // Called just before this Command runs the first time
    protected void initialize() {
        shooterSubsystem.initialize();
        startTime = Timer.getFPGATimestamp();
        System.out.println("Got Start Time " + startTime);
        isFinished = false;
    }

    // Called repeatedly when this Command is scheduled to run
    protected void execute() {
        /*
         * Switch case down below does not work in this application, yet may be
         * used elsewhere.
         */
        switch (shooterMode) { // case 0 may or may not be used...
            case 0:
                System.out.println("Ingesting");
                shooterSubsystem.ingest();
                isFinished = true;
                break;
            case 1:
                System.out.println("Stopping");
                shooterSubsystem.stop();
                isFinished = true;
                break;
            case 2:
                System.out.println("Shooting vex # " + Timer.getFPGATimestamp() + " @ " + (startTime + kShotDelay));
                shooterSubsystem.spinUpShooter();
                if (Timer.getFPGATimestamp() > (startTime + kShotDelay)) {
                    System.out.println("Shot");
                    shooterSubsystem.shoot();
                    isFinished = true;
                }
                break;
        }
    }

    // Make this return true when this Command no longer needs to run execute()
    protected boolean isFinished() {
        return isFinished;
    }

    // Called once after isFinished returns true
    protected void end() {
    }

    // Called when another command which requires one or more of the same
    // subsystems is scheduled to run
    protected void interrupted() {
        end();
    }
}
